<?php
// +----------------------------------------------------------------------
// | KongQiAdminBase [ Laravel快速后台开发 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2012~2019 http://www.kongqikeji.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: kongqi <531833998@qq.com>`
// +----------------------------------------------------------------------

namespace App\Plugin\HostServer\Migrations;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

/**
 * 创建数据库
 * Class Seed
 * @package App\Plugin\HostServer\Migrations
 */
class Install
{
    public function up()
    {
        $this->pifxed = \Illuminate\Support\Facades\DB::connection()->getTablePrefix();
        if (!Schema::hasTable('pn_host_sv_categories')) {
            Schema::create('pn_host_sv_categories', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->unsignedInteger('parent_id')->default(0)->comment('上级id');
                $table->string('path_level')->nullable()->comment('层级顺序');
                $table->string('group_type', 120)->index('group_type')->comment('类型');
                $table->string('name', 120)->comment('名称');
                $table->string('ename', 120)->index('ename')->nullable()->comment('调用英文名字');
                $table->string('module', 120)->index('module')->nullable()->comment('模块类型');
                $table->string('thumb')->nullable()->comment('图片');
                $table->string('mthumb')->nullable()->comment('移动图片');
                $table->string('banner')->nullable()->comment('banner图片');
                $table->string('mbanner')->nullable()->comment('banner图片');
                $table->string('intro')->nullable()->comment('介绍');
                $table->string('sort_type')->comment('排序')->default('id,desc');
                $table->smallInteger('pagesize')->commnet('列表显示数量')->nullable();
                $table->integer('sort')->default(0)->comment('排序');
                $table->tinyInteger('is_checked')->default(1)->comment('状态1:启用,0:禁用');
                $table->string('seo_title', 200)->nullable()->comment('SEO标题');
                $table->string('seo_key', 255)->nullable()->comment('SEO关键词');
                $table->string('seo_desc', 255)->nullable()->comment('SEO描述');
                $table->integer('view_numbers')->default(0)->comment('查阅人数');
                $table->timestamps();
            });

            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_categories comment '主机分类表'");

        }
        if (!Schema::hasTable('pn_host_sv_users')) {
            Schema::create('pn_host_sv_users', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->unsignedInteger('user_id')->default(0)->comment('上级id');
                $table->string('name')->comment('名称');
                $table->string('email')->index('email')->comment('邮箱账号');
                $table->decimal('money', 14, 2)->default(0)->comment('账号金额');
                $table->string('buy_password')->nullable()->comment('交易密码');
                $table->string('remember_token')->comment('记住密码token')->nullable();
                $table->string('password')->nullable()->comment('密码');
                $table->string('origin_password')->nullable()->comment('原始密码');
                $table->integer('sort')->default(0)->comment('排序');
                $table->string('regist_ip')->comment('注册ip')->nullable();
                $table->string('email_token')->comment('email_token认证token')->nullable();
                $table->tinyInteger('is_checked')->default(1)->comment('状态1:启用,0:禁用');
                $table->timestamp('email_verified_at')->comment('邮箱验证时间')->nullable();
                $table->integer('server_end_numbers')->default(0)->comment('服务器到期时间数量');
                $table->integer('server_numbers')->default(0)->comment('服务器数量');
                $table->integer('notify_number')->default(0)->comment('通知数量');
                $table->timestamps();
                $table->softDeletes();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_users comment '会员表'");
        }
        if (!Schema::hasTable('pn_host_sv_user_logs')) {
            Schema::create('pn_host_sv_user_logs', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->unsignedInteger('user_id')->default(0)->comment('上级id');
                $table->string('name')->comment('名称');
                $table->string('group_type')->comment('类型');
                $table->string('ip')->comment('IP')->nullable();
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_user_logs comment '会员日志表'");
        }
        if (!Schema::hasTable('pn_host_sv_user_money_logs')) {
            Schema::create('pn_host_sv_user_money_logs', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('user_id')->index('user_id')->comment('会员id');
                $table->decimal('before_money', 20, 2)->default(0)->comment('变动之前金额');
                $table->decimal('after_money', 20, 2)->default(0)->comment('变动之后金额');
                $table->string('type')->default('1')->comment('1充值,2新购，3续费，4提现，5退款');
                $table->string('model_type')->nullable('')->comment('来源类型');
                $table->integer('model_id')->default(0)->comment('来源id')->nullable();
                $table->decimal('money', 20, 2)->comment('变动金额');
                $table->string('mark')->nullable()->comment('备注');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_user_money_logs comment '会员资金变动表'");
        }
        if (!Schema::hasTable('pn_host_sv_system_logs')) {
            Schema::create('pn_host_sv_system_logs', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('order_id')->index('order_id')->unsigned()->comment('订单ID');
                $table->integer('user_id')->index('user_id')->unsigned()->comment('会员id');
                $table->decimal('money', 20, 2)->comment('交易金额');
                $table->string('name')->nullable()->comment('来源描述');
                $table->timestamp('pay_ok_at')->nullable()->comment('支付成功时间');
                $table->tinyInteger('status')->default(1)->comment('状态:1交易成功,2处理中,3交易失败');
                $table->string('type')->index('type')->default(1)->comment('交易类型:1充值,2:购买服务器,3:续费服务器，4:退款');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_system_logs comment '系统资金变动表'");
        }
        if (!Schema::hasTable('pn_host_sv_goods')) {
            Schema::create('pn_host_sv_goods', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('sort')->default(0)->comment('排序');
                $table->tinyInteger('is_checked')->default(1)->comment('状态1:启用,0:禁用');
                $table->tinyInteger('is_hot')->default(0)->comment('热门1:是,0:默认');

                $table->string('name')->comment('名称');
                $table->integer('category_id')->default(0)->index('category_id')->comment('所属分类');
                $table->integer('config_level_id')->default(0)->index('config_level_id')->comment('配置级别');
                $table->string('intro', 2000)->comment('简单介绍')->nullable();
                $table->decimal('money', 20, 2)->default(0)->comment('价格');
                $table->string('cpu')->nullable()->comment('CPU核数');
                $table->string('memory')->nullable()->comment('内存大小');
                $table->string('disk')->comment('硬盘大小')->nullable();
                $table->string('disk_type')->comment('硬盘类型')->nullable();
                $table->string('feature')->comment('特点')->nullable();
                $table->string('defense_feature')->comment('防御特点')->nullable();
                $table->string('bandwidth')->nullable()->comment('带宽');
                $table->string('area')->nullable()->comment('地区');
                $table->string('support_system')->nullable()->comment('支持系统类型');
                $table->unsignedInteger('admin_id')->default(0)->comment('发布人id');
                $table->string('seo_title', 200)->nullable()->comment('SEO标题');
                $table->string('seo_key', 255)->nullable()->comment('SEO关键词');
                $table->string('seo_desc', 255)->nullable()->comment('SEO描述');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_goods comment '产品表'");
        }

        if (!Schema::hasTable('pn_host_sv_system_goods')) {
            Schema::create('pn_host_sv_system_goods', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('sub_id')->index('sub_id')->comment('系统id');
                $table->integer('category_id')->default(0)->index('category_id')->comment('所属分类id');
                $table->integer('good_id')->index('good_id')->comment('产品id');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_system_goods comment '产品系统关联表'");
        }
        if (!Schema::hasTable('pn_host_sv_searchs')) {
            Schema::create('pn_host_sv_searchs', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('item')->comment('栏目名称');
                $table->integer('checked')->default(0)->comment('状态。0：不显示；1：显示');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_searchs comment '搜索栏目设置表'");
        }
        if (!Schema::hasTable('pn_host_sv_orders')) {
            Schema::create('pn_host_sv_orders', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('model_id')->index('model_id')->comment('产品id');
                $table->string('model_type')->index('model_type')->comment('产品类型');
                $table->integer('user_id')->default(0)->index('user_id')->comment('会员id');
                $table->string('order_sn', 60)->index('order_sn')->comment('订单号');
                $table->string('user_name')->comment('使用会员名称');
                $table->string('name')->comment('产品名称');
                $table->decimal('money', 20, 2)->default(0)->comment('产品单价');
                $table->decimal('total', 20, 2)->default(0)->comment('成交总价');
                $table->string('ip')->nullable()->comment('服务ip');
                $table->string('root_name')->nullable()->comment('root账号');
                $table->string('root_password')->nullable()->comment('密码');
                $table->string('bt_url')->nullable()->comment('BT地址');
                $table->string('bt_name')->nullable()->comment('BT账号');
                $table->string('bt_password')->nullable()->comment('BT密码');
                $table->integer('month')->default(1)->comment('购买月数');
                $table->string('system')->nullable()->comment('系统类型');
                $table->string('user_mark')->nullable()->comment('会员备注');
                $table->string('mark')->nullable()->comment('系统备注');
                $table->text('data')->comment('产品数据包')->nullable();
                $table->tinyInteger('status')->default(1)->comment('订单状态,1:购买成功,0未支付,2退款');
                $table->timestamp('buy_at')->nullable()->comment('生效开始时间');
                $table->timestamp('end_at')->nullable()->comment('到期时间');
                $table->timestamp('refund_at')->nullable()->comment('退款时间');
                $table->date('notify_day')->nullable()->comment('通知日期');
                $table->timestamps();
                $table->softDeletes();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_orders comment ' 订单表'");
        }
        if (!Schema::hasTable('pn_host_sv_order_logs')) {
            Schema::create('pn_host_sv_order_logs', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('order_id')->index('order_id')->unsigned()->comment('订单ID');
                $table->string('name', 255)->comment('事件名称');
                $table->tinyInteger('from_status')->default(-1)->comment('订单开始状态');
                $table->tinyInteger('to_status')->default(-1)->comment('订单当前状态');
                $table->string('mark', 255)->nullable()->comment('备注');
                $table->unsignedInteger('handle_id')->default(0)->comment('操作人id');
                $table->string('handle_name', 30)->nullable()->comment('操作人姓名');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_order_logs comment '订单日志'");
        }
        if (!Schema::hasTable('pn_host_sv_cards')) {
            Schema::create('pn_host_sv_cards', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('user_id')->default(0)->index('user_id')->comment('使用会员id');
                $table->string('user_name')->nullable()->comment('使用会员名称');
                $table->string('card_number')->unique()->comment('卡密码');
                $table->decimal('money', 20, 2)->default(0)->comment('金额');
                $table->timestamp('user_at')->nullable()->comment('使用时间');
                $table->tinyInteger('status')->default(0)->comment('使用状态:1使用,0未使用');
                $table->timestamp('invalid_at')->comment('过期时间')->nullable();
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_cards comment '卡密表'");
        }
        if (!Schema::hasTable('pn_host_sv_email_logs')) {
            Schema::create('pn_host_sv_email_logs', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('user_id')->index('user_id')->default(0)->unsigned()->comment('会员id');
                $table->integer('model_id')->index('model_id')->default(0)->unsigned()->comment('对应ID');
                $table->string('model_type')->index('model_type')->default(0)->comment('对应类型');
                $table->string('name')->nullable()->comment('邮箱标题');
                $table->text('content')->nullable()->comment('邮件内容');
                $table->string('to_email')->nullable()->comment('接收者');
                $table->tinyInteger('type')->default(1)->comment('类型1:到期提醒');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_email_logs comment '邮箱提示信息'");
        }
        if (!Schema::hasTable('pn_host_sv_navs')) {
            Schema::create('pn_host_sv_navs', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->unsignedInteger('parent_id')->default(0)->comment('上级id');
                $table->integer('sort')->default(0)->comment('排序');
                $table->tinyInteger('is_checked')->default(1)->comment('状态1:启用,0:禁用');
                $table->tinyInteger('is_blank')->default(0)->comment('新建打开:1是,0:否');

                $table->string('name')->comment('名称');
                $table->string('url')->comment('链接地址');
                $table->string('group_type')->index()->comment('类型')->default('nav');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_navs comment '导航表'");
        }
        if (!Schema::hasTable('pn_host_sv_pages')) {
            Schema::create('pn_host_sv_pages', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('sort')->default(0)->comment('排序');
                $table->tinyInteger('is_checked')->default(1)->comment('状态1:启用,0:禁用');
                $table->string('name')->comment('名称');
                $table->string('sub_name')->nullable()->comment('简短名称');
                $table->text('content')->comment('正文');
                $table->string('group_type')->index()->comment('类型')->default('page');
                $table->string('seo_title', 200)->nullable()->comment('SEO标题');
                $table->string('seo_key', 255)->nullable()->comment('SEO关键词');
                $table->string('seo_desc', 255)->nullable()->comment('SEO描述');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_pages comment '单页表'");
        }
        if (!Schema::hasTable('pn_host_sv_numbers')) {
            Schema::create('pn_host_sv_numbers', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('sort')->default(0)->comment('排序');
                $table->tinyInteger('is_checked')->default(1)->comment('状态1:启用,0:禁用');
                $table->string('name')->comment('名称');
                $table->integer('number')->comment('初始化数量');
                $table->string('range_number')->default('0|10')->comment('变化随机数');
                $table->date('to_day')->nullable()->comment('今天变化日期');
                $table->tinyInteger('type')->default(1)->comment('类型,1表示每天增加，2固定');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_numbers comment '虚拟数据表'");
        }
        if (!Schema::hasTable('pn_host_sv_codes')) {
            Schema::create('pn_host_sv_codes', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('account')->index('account')->comment('账号');
                $table->string('type')->index('type')->comment('类型：mobile,email');
                $table->string('code');
                $table->tinyInteger('status')->default(0)->comment('是否使用了');
                $table->timestamps();

            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_codes comment '验证码表'");
        }
        if (!Schema::hasTable('pn_host_sv_doings')) {
            Schema::create('pn_host_sv_doings', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('type')->index();
                $table->integer('type_id')->index();
                $table->string('mark')->nullable()->comment('备注');
                $table->date('to_day')->nullable()->comment('操作日期');

                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_doings comment '操作记录表'");
        }
        if (!Schema::hasTable('pn_host_sv_domains')) {
            Schema::create('pn_host_sv_domains', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('name')->index()->comment('域名后缀类型');
                $table->string('intro')->nullable()->comment('说明');
                $table->decimal('origin_money',20,0)->default(0)->comment('原来价格');
                $table->decimal('register_money',20,0)->default(0)->comment('注册价格');
                $table->decimal('renewal_money',20,0)->default(0)->comment('续费价格');
                $table->decimal('migrate_money',20,0)->default(0)->comment('迁移价格');
                $table->integer('sort')->default(0)->comment('排序');
                $table->tinyInteger('is_checked')->default(1)->comment('状态1:启用,0:禁用');
                $table->tinyInteger('is_hot')->default(0)->comment('热门:启用,0:禁用');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_domains comment '操作记录表'");
        }

        //域名订单
        if (!Schema::hasTable('pn_host_sv_domain_orders')) {
            Schema::create('pn_host_sv_domain_orders', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->integer('user_id')->default(0)->index('user_id')->comment('会员id');
                $table->string('order_sn', 60)->index('order_sn')->comment('订单号');
                $table->string('user_name')->comment('使用会员名称');
                $table->string('name')->comment('域名名称');
                $table->decimal('money', 20, 2)->default(0)->comment('API原价单价');
                $table->decimal('total', 20, 2)->default(0)->comment('成交总价');
                $table->integer('year_numbers')->default(1)->comment('购买年数');
                $table->integer('check_year_numbers')->default(0)->comment('审核的年数要处理的');
                $table->string('mark')->nullable()->comment('系统备注');
                $table->text('data')->comment('数据包')->nullable();
                $table->tinyInteger('status')->default(1)->comment('订单状态,1:购买成功,0未支付,2退款，3.购买成功，但需要后台人员审核补充');
                $table->timestamp('buy_at')->nullable()->comment('生效开始时间');
                $table->timestamp('end_at')->nullable()->comment('到期时间');
                $table->timestamp('refund_at')->nullable()->comment('退款时间');
                $table->date('notify_day')->nullable()->comment('通知日期');
                $table->string('domain_user')->comment('域名持有者')->nullable();
                $table->timestamps();
                $table->softDeletes();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_domain_orders comment ' 域名订单表'");
        }
        //域名订单
        if (!Schema::hasTable('pn_host_sv_domain_setings')) {
            Schema::create('pn_host_sv_domain_setings', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('domain')->nullable()->comment('域名');
                $table->integer('user_id')->default(0)->index('user_id')->comment('会员id');
                $table->integer('order_id')->index('order_id')->comment('订单ID');
                $table->string('type')->nullable()->comment('类型');
                $table->text('content')->comment('数据包');
                $table->timestamps();
            });
            \Illuminate\Support\Facades\DB::statement("ALTER TABLE " . $this->pifxed . "pn_host_sv_domain_setings comment ' 域名解析表'");
        }

    }
}
